package com.sui.bigdata.sml.web.repository.mapper;

import com.sui.bigdata.sml.web.repository.model.NodeGroup;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author songhaicheng
 * @date 2019/11/5 10:00
 * @description
 * @reviewer
 */
@Repository
public interface NodeGroupMapper {

    @Insert("insert into node_group(experiment_id,user_id,node_ids,az_project_name) " +
            "values(#{experimentId},#{userId},#{nodeIds},#{azProjectName})")
    @Options(useGeneratedKeys = true)
    int insert(NodeGroup nodeGroup);

    @Select("select * from node_group where id=#{id}")
    NodeGroup get(Long id);

    @Select("select * from node_group where experiment_id=#{experimentId} order by create_time desc")
    List<NodeGroup> listByExperimentId(Long experimentId);

    @Select("select * from node_group where experiment_id=#{experimentId} and status in (0, 1) order by create_time desc")
    List<NodeGroup> listOngoingsByExperimentId(Long experimentId);

    @Update("update node_group set experiment_id=#{experimentId},user_id=#{userId},node_ids=#{nodeIds}," +
            "status=#{status},az_project_name=#{azProjectName} where id=#{id}")
    int update(NodeGroup nodeGroup);

    @Delete("<script>delete from node_group where id=" +
            "<choose>" +
            "<when test='id!=null'>" +
            "   #{id}" +
            "</when>" +
            "<otherwise>" +
            "   -1" +
            "</otherwise>" +
            "</choose>" +
            "</script>")
    int delete(@Param("id") Long id);

}
